﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Web;
using System.Web.SessionState;
using DTcms.Web.UI;
using DTcms.Common;

namespace DTcms.Web.m
{
    /// <summary>
    /// shicaiquan 的摘要说明
    /// </summary>
    public class shicaiquan : IHttpHandler, IRequiresSessionState
    {
        public void ProcessRequest(HttpContext context)
        {
            string  _keyword = DTRequest.GetQueryString("txtkeyword");
            string _province = DTRequest.GetQueryString("province");
            StringBuilder strTxt = new StringBuilder();
            strTxt.Append("{");
            //获取供应信息
            BLL.quanzi bll = new BLL.quanzi();
            string sql = "1=1 ";
            if (_keyword + "" != "" && _keyword!= "undefined") {
                sql += " and title like '%"+_keyword+"%'";
            }
            if (_province + "" != "" && _province != "undefined")
            {
                sql += " and province_id in (select id from ch_province where province_name like  '%" + _province + "%' ) ";
            }
            DataSet ds = bll.GetList(0, sql, "sort_id asc,id asc");
            //如果记录存在
            if (ds.Tables[0].Rows.Count > 0)
            {
                strTxt.Append("\"quanzi_list\":[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = ds.Tables[0].Rows[i];
                    strTxt.Append("{");
                    strTxt.Append("\"id\":" + dr["id"]);
                    strTxt.Append(",\"title\":\"" + dr["title"] + "\"");
                    strTxt.Append("}");
                    //是否加逗号
                    if (i < ds.Tables[0].Rows.Count - 1)
                    {
                        strTxt.Append(",");
                    }
                }
                strTxt.Append("]");
            }
            strTxt.Append("}");
            context.Response.Write(strTxt.ToString());
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}